package com.saturn.titan.core.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.saturn.titan.core.bean.Node;
import com.saturn.titan.core.repository.mybatis.NodeDao;

@Component
@Transactional(readOnly = true)
public class CollectedCommentService {

	private static Logger logger = LoggerFactory.getLogger(CollectedCommentService.class);

	@Autowired
	private NodeDao nodeDao;

	@Transactional(readOnly = false)
	public Node findNodeById(Long i) {
		logger.debug("test");
		Node node = nodeDao.selectById(i);
		return node;
	}
	
	@Transactional(readOnly = false)
	public void insert(Node node) {
		logger.debug("test");
		System.out.println("test insert");
		nodeDao.insert(node);
	}
	
	/*
	 * 事务回滚测试
	 */
	@Transactional(readOnly = false)
	public void testTransactional(Node node) throws Exception {
		logger.debug("insert one");
		nodeDao.insert(node);
		logger.debug("insert done!");
		throw new RuntimeException();
	}
	
	@Transactional(readOnly = false)
	public void testUpdate(Node node) throws Exception {
		nodeDao.update(node);
	}
}
